package com.config.log;

import com.controller.template.ResultCode;
import com.util.HttpUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import javax.servlet.http.HttpServletRequest;

/**
 * 日志操作任务创建工厂
 *
 * @author fengshuonan
 * @date 2016年12月6日 下午9:18:27
 */
public class LogFactory {

    public static final Logger logger = LoggerFactory.getLogger(LogFactory.class);

    /**
     * 错误日志处理
     */
    public static void printErrLog(Exception e, String serviceName, String params) {
        logger.error(BizConstants.LOG_ERROR_FORMAT, serviceName, params, e.getMessage(), e);
    }

    /**
     * 错误日志处理
     */
    public static void printErrLog(String errorMsg) {
        logger.error(BizConstants.LOG_ERROR_FORMAT_SIMPLE, errorMsg);
    }

    /**
     * 请求日志处理
     */
    public static void printReqLog(HttpServletRequest request, String params) {
        logger.info(BizConstants.LOG_REQUEST_FORMAT,
                request.getRequestURL().toString(),
                params,
                request.getMethod(),
                HttpUtils.getIpAddress(request));
    }

    /**
     * API权限日志处理
     */
    public static void printPermissionLog(HttpServletRequest request) {
        logger.warn(BizConstants.LOG_PERMISSION_FORMAT,
                request.getRequestURL().toString(),
                HttpUtils.getIpAddress(request),
                ResultCode.IDENTITY_INFORMATION_ERROR.getDesc());
    }



}
